<%@ page pageEncoding="UTF-8"%>
<%@ taglib prefix="isperp" uri="/WEB-INF/tlds/isperp.tld"%>

<script type="text/javascript">
	function menuTree_onNodeClick(event, treeId, treeNode) {
		//alert(treeNode.treenodePath);
		//alert(	JSON.stringify(treeNode));

		menuGrid.search({
			"field" : "parent_id",
			"op" : "eq",
			"data" : treeNode.id
		});
	}
	
	function getMenuTreeNode() {
		var node = menuTree.getSelectedNode();
		if (node !=undefined) {
			return "parentId=" + node.id;
		}
		isperp.alert("请选择节点！");
		return false;
	}

	function syncMenuToWechat() {
		$.post('wechat/cp/menu/createWechatCpMenu', function(data) {
			if (data.success) {
				isperp.tooltip('同步成功')
			} else {
				isperp.errorAlert('同步失败：' + data.data);
			}
		});
		return false;
	}
</script>
<div class="box no-border clearfix">

	<div class="box-left" style="width:280px">
		<isperp:tree id="menuTree" cusEditUrl="wechat/cp/menu/edit"
			cusDeleteUrl="wechat/settingConfig/delete">
			<isperp:async enable="true" url="wechat/cp/menu/getTree?showRoot=1">
			</isperp:async>
			<isperp:callback onClick="menuTree_onNodeClick">
			</isperp:callback>
			<isperp:edit enable="true" showRemoveBtn="false"
				showRenameBtn="false"></isperp:edit>
		</isperp:tree>
	</div>

	<div class="box-right" style="margin-left:290px">

		<div class="box no-border">
			<div class="header">
				<h2>子系统菜单详细列表</h2>
			</div>

			<isperp:grid url="wechat/cp/menu/list" gridId="menuGrid"
				cusFormatterActions="true" cusEditUrl="wechat/cp/menu/edit"
				cusDeleteUrl="wechat/cp/menu/delete"
				ondbClickRowEvent="menuGrid.edit(rowid);" showSearchbar="false"
				beforeCreateAction="getMenuTreeNode();"
				afterActionsSuccess="menuTree.reload();">

				<jsp:attribute name="toolbar">
	 				<isperp:toolbar id="menuToolbar">
		 				<isperp:button id="menuCreate" cssClass="nui-mainbtn"
							icon="icon-plus" text="新增下级菜单" onclick="menuGrid.create();"></isperp:button>
		 				 
		 				 <isperp:button id="menuCreateWechatMenu" icon="icon-plus"
							text="同步菜单至微信服务台" onclick="syncMenuToWechat();"></isperp:button>
		 				
		 				
		 				 <isperp:button id="menuCreateWechatGet" icon="icon-plus"
							text="获取微信菜单"
							onclick="$.post('wechat/cp/menu/getWechatCpMenu',function(data){isperp.alert(data);});return false;"></isperp:button>
		 				
	 				</isperp:toolbar>
				 </jsp:attribute>
				<jsp:body> 
					<isperp:column name="id" title="id" hidden="true"></isperp:column>
					<isperp:column name="parentId" title="parentId" hidden="true"></isperp:column>
					<isperp:column name="name" title="名称" width="100">
					</isperp:column>
					<isperp:column name="treenodeNamePath" title="路径" width="200">
					</isperp:column>
					 <isperp:column name="menuType" title="菜单类型" width="60">
					</isperp:column>
						 <isperp:column name="menuKey" title="菜单Key" width="120">
					</isperp:column>
				    <isperp:column name="url" title="节链接地址" width="200">
					</isperp:column>
					 
					<isperp:column name="orderNum" align="center" title="排序" width="40">
					</isperp:column>
				</jsp:body>

			</isperp:grid>
		</div>
	</div>
</div>
